<template>
   <div class="app-container">
      <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
         <el-form-item label="项目名称" prop="name">
            <el-input
               v-model="queryParams.name"
               placeholder="请输入项目名称"
               clearable
               style="width: 200px"
               @keyup.enter="handleQuery"
            />
         </el-form-item>
         <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
         </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
         <el-col :span="1.5">
            <el-button
               type="primary"
               plain
               icon="Plus"
               @click="handleAdd"
               v-hasPermi="['system:eaOutdoorProject:add']"
            >新增</el-button>
         </el-col>
         <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="list">
         <el-table-column label="序号" align="center" type="index" />
         <el-table-column label="项目名称" align="center" prop="name" show-overflow-tooltip />
         <el-table-column label="项目地址" align="center" prop="url"  />
         <el-table-column label="创建时间" align="center" prop="createTime"  />
         <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
               <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"
               v-hasPermi="['system:eaOutdoorProject:edit']">修改</el-button>
               <el-button link type="primary" icon="Delete"
               @click="handleDelete(scope.row)" v-hasPermi="['system:eaOutdoorProject:remove']" >删除</el-button>
            </template>
         </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <!-- 添加或修改公告对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
         <el-form ref="formRef" :model="form" :rules="rules" label-width="80px">
            <el-row>
               <el-col :span="24">
                <el-form-item label="项目名称" prop="name">
                   <el-input v-model="form.name" placeholder="请输入项目名称" />
                </el-form-item>
               </el-col>
               <el-col :span="24">
                <el-form-item label="项目地址" prop="url">
                   <el-input v-model="form.url" placeholder="请输入项目地址" />
                </el-form-item>
               </el-col>
            </el-row>
         </el-form>
         <template #footer>
            <div class="dialog-footer">
               <el-button type="primary" @click="submitForm">确 定</el-button>
               <el-button @click="cancel">取 消</el-button>
            </div>
         </template>
      </el-dialog>
   </div>
</template>

<script>
import { listEaOutdoorProject, getEaOutdoorProject, addEaOutdoorProject, updateEaOutdoorProject,
delEaOutdoorProject } from "@/api/roadside/roadProject";
export default {
  name: 'RoadProject',
  dicts: ['is_yes_no'],
  components: {  },
  data() {
    return {
      form: {},// 表单参数
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      queryParams: {// 查询参数
        pageNum: 1,
        pageSize: 10,
        status:null,
        issue:null,
      },
      // 总条数
      total: 0,
      rules: {
        name: [{ required: true, message: "项目名称不能为空", trigger: "blur" }],
        url: [{ required: true, message: "项目地址不能为空", trigger: "blur" }],
      },
      list:[],//页面数据
    };
  },
  mounted(){
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true;
      listEaOutdoorProject(this.queryParams).then(response => {
        this.list = response.rows || [];
        this.total = response.total || 0;
        this.loading = false;
      });
    },
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    handleAdd() {
      this.open = true;
      this.reset();
      this.title = "添加路测项目信息";
    },
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      this.open = true;
      this.title = "修改路测项目信息";
      getEaOutdoorProject(id).then(response => {
        let data = response.data || {}
        this.form = {...data,};
      });
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("formRef");
    },
    submitForm() {
      this.$refs["formRef"].validate(valid => {
        if (valid) {
          let form = {...this.form}
          if (this.form.id != undefined) {
            updateEaOutdoorProject(form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false;
              this.getList();
            });
          } else {
            addEaOutdoorProject(form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    cancel() {
      this.open = false;
      this.reset();
    },
    handleDelete(row) {//删除
      const del_ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除编号为"' + del_ids + '"的数据项？').then(function() {
        return delEaOutdoorProject(del_ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryRef");
      this.handleQuery();
    },
  }
}
</script>
